package cn.tedu.ivos.application.service.impl;

import cn.tedu.ivos.application.mapper.ApplicationMapper;
import cn.tedu.ivos.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.application.pojo.entity.Application;
import cn.tedu.ivos.application.service.ApplicationService;
import cn.tedu.ivos.audit.service.impl.AuditService;
import cn.tedu.ivos.base.enums.ApplicationStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Slf4j
@Service
public class ApplicationServiceImpl implements ApplicationService {

    @Autowired
    ApplicationMapper applicationMapper;
    @Autowired
    AuditService auditService;
    @Override
    public void save(ApplicationSaveParam applicationSaveParam) {
        log.debug("保存申请单,参数={}", applicationSaveParam);
        Application application = new Application();
        BeanUtils.copyProperties(applicationSaveParam, application);
        //申请单的初始状态为"已发起"
        application.setStatus(ApplicationStatusEnum.PENDING.getCode());
        application.setCreateTime(new Date());
        applicationMapper.insert(application);
        //还需要为此申请单生成对应的审批单数据
        auditService.insertAudit(application);
    }
}
